package cn.maidouya.quartz.jobs;
import cn.maidouya.order.service.IAdoptOrderService;
import cn.maidouya.quartz.constants.QuartzConstants;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.json.JSONString;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

public class MainJob implements Job {
    @Autowired
    private IAdoptOrderService adoptOrderService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        Object paramsObj = jobDataMap.get("params");
        System.err.println("======================" +paramsObj);
        if(paramsObj != null){
            /*QuartzJobInfo info = JSONObject.parseObject(paramsObj.toString(), QuartzJobInfo.class);*/
            QuartzJobInfo info = JSONObject.parseObject(paramsObj.toString(), QuartzJobInfo.class);

            System.err.println("========info==============" +info);
            switch(info.getType()){
                case QuartzConstants.ORDER_ADOPT_TYPE_CANCEL:
                    Object orderIdTmp = info.getParams().get("orderId");
                    if(orderIdTmp != null){
                        adoptOrderService.quartzCancel(Long.valueOf(orderIdTmp.toString()));
                    }
                    break;
                case 2 :
                    //语句
                    break; //可选
                //你可以有任意数量的case语句
                default : //可选
                    //语句
            }
        }
    }
}